@extends('.coupons_admin/layouts')
@section('style')
    <meta name="_token" content="{{ csrf_token() }}"/>
    <style>
        .staff-th{
            text-align: center;
            color: #676767;
        }
        .staff-td{
            text-align: center;
            color: #676767;
        }
    </style>
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap-datetimepicker.min.css')}}">
    <link rel="stylesheet" href="{{url('css/search.css')}}">
@stop
@section('content')
    <div class="content-wrapper" style="background-color: white">
        <section class="content">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="box box-info"
                         style="padding-top: 0px;margin-top: 0px;border-top: 0px;border-bottom: solid 1px #0080ff;">
                        <div class="box-body" style="">
                            <div class="row">
                                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="margin-top: 1%">
                                    <a href="{{url('generalAdmin/index')}}" title="返回首页" style="float: left"><i class="fa fa-home fa-2x"
                                                                                                                style="width: 100%;color: #009aff">
                                        </i></a>
                                    <span style="font-size: 20px;float: left;color: #009aff">&nbsp优惠卷管理</span>
                                    <div class="clear"></div>
                                </div>
                                <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12 col-lg-offset-6 col-md-offset-4 btn-div">
                                    <button type="button" class="btn btn-info div-btn" data-toggle="modal" data-target="#admin-add-userModal" style="background: #009aff;float: right;margin-left: 1%;margin-top: 1%">添加优惠券</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            @include('public/alert')
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th class="staff-th">#</th>
                                <th class="staff-th">优惠券名称</th>
                                <th class="staff-th">类型</th>
                                <th class="staff-th">优惠金额</th>
                                <th class="staff-th">数量(个)</th>
                                <th class="staff-th">已领取(个)</th>
                                <th class="staff-th">状态</th>
                                <th class="staff-th">开始时间</th>
                                <th class="staff-th">截止时间</th>
                                <th class="staff-th">创建时间</th>
                                <th class="staff-th">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if($coupons->isEmpty())
                                <tr>
                                    <td colspan="9" style="text-align: center;color: #676767">暂无数据</td>
                                </tr>
                            @else
                                @php($coupons_state=config("config.coupons_state"))
                                @foreach($coupons as $k=>$v)
                                    <tr>
                                        <td class="staff-td">{{$k+1}}</td>
                                        <td class="staff-td">{{$v['coupons_name']}}</td>
                                        <td class="staff-td">{{config("config.coupons_type")[$v['coupons_type']]}}</td>
                                        <td class="staff-td">¥{{$v['coupons_amount']}}</td>
                                        <td class="staff-td">{{$v['coupons_num']}}</td>
                                        <td class="staff-td">{{$v['remain_num']}}</td>
                                        <td class="staff-td">{{$coupons_state[$v['coupons_state']]}}</td>
                                        <td class="staff-td">{{date("Y-m-d H:i",strtotime($v['started_at']))}}</td>
                                        <td class="staff-td">{{date("Y-m-d H:i",strtotime($v['closed_at']))}}</td>
                                        <td class="staff-td">{{date("Y-m-d H:i",strtotime($v['created_at']))}}</td>
                                        <td class="staff-td">
                                            <a href="{{url('Admin/couponsAdmin/delCoupons',['id'=>$v['id']])}}" onclick="return confirm('确定要删除吗?')">删除</a>
                                            @if(in_array($v['coupons_state'],[0,1]))
                                                <a href="{{url('Admin/couponsAdmin/submitAudit',['id'=>$v['id']])}}" onclick="return confirm('提交审核')">提交审核</a>
                                                <a href="#" class="change"
                                                   hide_id="{{$v['id']}}"
                                                   coupons_name="{{$v['coupons_name']}}"
                                                   type="{{$v['coupons_type']}}"
                                                   amount="{{$v['coupons_amount']}}"
                                                   num="{{$v['coupons_num']}}"
                                                   started_at="{{$v['started_at']}}"
                                                   closed_at="{{$v['closed_at']}}"
                                                   data-toggle="modal"
                                                   data-target="#editCouponsModal">修改</a>

                                                @else
                                                提交审核 修改
                                            @endif

                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                        <div class="btn-page">
                               {{ $coupons->links()}}
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    @include('public/addCouponsModal')
    @include('public/editCouponsModal')
@stop
@section('javascript')
    <script src="{{asset('admin_assets/js/bootstrap-datetimepicker.min.js')}}"></script>
    <script src="{{asset('js/ip.js')}}"></script>
    <script>
        $(".form_datetime").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            autoclose: true,
            todayBtn: true,
            minuteStep: 10,
            language: "en"
        });
        $(".change").click(function () {
            $("#hide_id").val($(this).attr('hide_id'));
            $("#coupons_name").val($(this).attr('coupons_name'));
            $("#coupons_type").val($(this).attr('type'));
            $("#coupons_amount").val($(this).attr('amount'));
            $("#coupons_number").val($(this).attr('num'));
            $("#coupons_started_at").val($(this).attr('started_at'));
            $("#coupons_closed_at").val($(this).attr('closed_at'));

        });
    </script>
@stop
